package com.example.nonacademic_education.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckRole;
import com.example.nonacademic_education.constant.Constant;
import com.example.nonacademic_education.data.request.FileItemGrantVo;
import com.example.nonacademic_education.entity.Department;
import com.example.nonacademic_education.entity.FileItemInfo;
import com.example.nonacademic_education.service.impl.FileItemInfoServiceImpl;
import com.example.nonacademic_education.util.R;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@RequestMapping("fileItem")
public class FileItemInfoController {
    @Resource
    private FileItemInfoServiceImpl fileItemInfoService;
    @GetMapping("getList")
    @SaCheckPermission("fileItem.query")
    public R getList(Integer page,Integer size,String name){
        return fileItemInfoService.getList(page,size,name);
    }
    @PostMapping("addOne")
    @SaCheckPermission("fileItem.add")
    public R addOne(@RequestBody FileItemInfo fileItemInfo){
        return fileItemInfoService.addOne(fileItemInfo);
    }
    @PutMapping("updateOne")
    @SaCheckPermission("fileItem.update")
    public R updateOne(@RequestBody FileItemInfo fileItemInfo){
        return fileItemInfoService.updateOne(fileItemInfo);
    }
    @DeleteMapping("deleteOne")
    @SaCheckPermission("fileItem.delete")
    public R deleteOne(Long id){
        return fileItemInfoService.deleteOne(id);
    }
    @GetMapping("getGrantList")
    @SaCheckPermission("fileItem.grant")
    public R getGrantList(Long itemId){
        return fileItemInfoService.getGrantList(itemId);
    }
    @PutMapping("updateGrant")
    @SaCheckPermission("fileItem.grant")
    public R updateGrant(@RequestBody FileItemGrantVo fileItemGrantVo){
//        return fileItemInfoService.updateGrant(fileItemGrantVo);
        return R.error("系统功能维护中，请联系管理员");
    }
    @GetMapping("getItemList")
    @SaCheckRole(Constant.NORMAL_ADMIN)
    public R getItemList(Long departmentId){
        return fileItemInfoService.getItemList(departmentId);
    }
    //todo 上传、更新、删除模板（查看模板，直接获取文件即可，放在一个单独的模板文件夹）/校验权限/精确控制/封号查询和解封
    @PostMapping("uploadTemplate")
    //@SaCheckRole(Constant.SUPER_ADMIN)
    public R uploadTemplate(@RequestBody MultipartFile file,Long fileItemId){
        return fileItemInfoService.uploadTemplate(file,fileItemId);
    }
    @DeleteMapping("deleteTemplate")
    //@SaCheckRole(Constant.SUPER_ADMIN)
    public R deleteTemplate(Long fileItemId){
        return fileItemInfoService.deleteTemplate(fileItemId);
    }
}
